#ifndef _PBVP_LIGHT_H
#define _PBVP_LIGHT_H

#ifdef WIN32
#include <windows.h>
#endif

#ifdef MACX_DEV
#include <gl.h>
#else
#include <GL/gl.h>
#endif

#include "color.h"
#include "../math/Vector4.h"

namespace PBVP {
	/// OpenGL Light Object
	class Light {
	public:
		/// <summary>
		/// Constructor
		/// </summary>
		Light();

		/// <summary>
		/// Color 
		/// </summary>
		/// <param name="clr1"></param>
		/// <param name="clr2"></param>
		/// <param name="clr3"></param>
		/// <param name="pos"></param>
		Light(const Color& clr1, const Color& clr2, const Color& clr3, const Vector4& pos)
		: m_Ambient(clr1), m_Diffuse(clr2), m_Specular(clr3), m_Position(pos) 
		{
			m_IsOn = true;
		}

		/// Copy Constructor
		Light(const Light& lit);

		/// Destructor
		~Light() {}

		/// Assignment operator
		Light& operator = (const Light& lit);

		/// Comparison operator
		bool operator == (const Light& lit) const;

		/// Accessors
		Color& ambient() {
			return m_Ambient;
		}
		const Color& ambient() const {
			return m_Ambient;
		}
		void setAmbient(const Color& c) {
			m_Ambient = c;
		}

		Color& diffuse() {
			return m_Diffuse;
		}
		const Color& diffuse() const {
			return m_Diffuse;
		}
		void setDiffuse(const Color& c) {
			m_Diffuse = c;
		}

		Color& specular() {
			return m_Specular;
		} 
		const Color& specular() const {
			return m_Specular;
		}
		void setSpecular(const Color& c) {
			m_Specular = c;
		}

		Vector4& position() {
			return m_Position;
		}
		const Vector4& position() const {
			return m_Position;
		}
		void setPosition(const Vector4& pos) {
			m_Position = pos;
		}
		/// Apply changes to OpenGL light configuration	
		void apply(GLenum id) {
			glLightfv(id, GL_AMBIENT, ambient().ptr());
			glLightfv(id, GL_DIFFUSE, diffuse().ptr());
			glLightfv(id, GL_SPECULAR, specular().ptr());
			glLightfv(id, GL_POSITION, position().ptr());
		}
		bool isOn() const {
			return m_IsOn;
		}
		void turnOnOff(bool on) {
			m_IsOn = on;
		}
	private:
		bool m_IsOn;
		Color m_Ambient;
		Color m_Diffuse;
		Color m_Specular;
		Vector4 m_Position;
	};
}
#endif 
